#include "Label.hpp"

sf::Font Label::defaultFont;
bool Label::fontLoaded = false;

Label::Label():InterfaceElement(0, 0, 100, 12){
    if(!fontLoaded){
        fontLoaded = defaultFont.loadFromFile("LiberationSans-Regular.ttf");
    }
    labelText.setFont(defaultFont);
    setString(12, sf::Color::White, sf::Text::Regular, "");
}

Label::Label(int x, int y, int fontSize, sf::Color fontColor, std::string text)
    :InterfaceElement(x, y, 0, 0){
    if(!fontLoaded){
        fontLoaded = defaultFont.loadFromFile("LiberationSans-Regular.ttf");
    }
   labelText.setFont(defaultFont);
   setString(fontSize, fontColor, sf::Text::Regular, text);
}

Label::Label(int x, int y, int fontSize, sf::Color fontColor):InterfaceElement(x, y, 0, 0){
     if(!fontLoaded){
        fontLoaded = defaultFont.loadFromFile("LiberationSans-Regular.ttf");
    }
   labelText.setFont(defaultFont);
   setString(fontSize, fontColor, sf::Text::Regular, "");
}

Label::Label(int x, int y, int fontSize, sf::Color fontColor, sf::Text::Style fontStyle, std::string text)
    :InterfaceElement(x, y, 0, 0){
        if(!fontLoaded){
            fontLoaded = defaultFont.loadFromFile("LiberationSans-Regular.ttf");
        }
    labelText.setFont(defaultFont);
    setString(fontSize, fontColor, fontStyle, text);
}

Label::Label(int fontSize, sf::Color fontColor, std::string text):InterfaceElement(0, 0, 0, 0){
    if(!fontLoaded){
        fontLoaded = defaultFont.loadFromFile("LiberationSans-Regular.ttf");
    }
    labelText.setFont(defaultFont);
    setString(fontSize, fontColor, sf::Text::Regular, text);
}

void Label::setString(std::string text){
    labelText.setString(text);
}

void Label::setString(int fontSize, sf::Color fontColor, sf::Text::Style fontStyle, std::string text){
    
    labelText.setCharacterSize(fontSize);
    labelText.setColor(fontColor);
    labelText.setString(text);
    labelText.setPosition(0, 0);
    labelText.setStyle(fontStyle);
    rect.width = labelText.getLocalBounds().width;
    rect.height = labelText.getLocalBounds().height;
}

void Label::draw(sf::RenderTarget& target, sf::RenderStates states) const{
    states.transform *= sf::Transform().translate((float)rect.left, (float)rect.top);
    target.draw(labelText, states);
}

std::string Label::getString(){
    return labelText.getString();
}